/**  
 * android原生通知发送  
 * @param content 通知内容  
 * @param data json对象，存储通知的隐藏数据，用于点击通知时接收使用  
 */
export function android_notify(content = '', data = {}) {
	// #ifdef APP-PLUS  
	var title = '通知标题';

	console.log('准备通知');
	console.log(plus.os.name);

	//Android平台下才使用此推送  
	if (plus.os.name != 'Android') {
		return false;
	}

	//随机生成通知ID  
	var NotifyID = Math.floor(Math.random() * 10000) + 1;

	var main = plus.android.runtimeMainActivity();
	var Context = plus.android.importClass("android.content.Context");
	var NotificationManager = plus.android.importClass("android.app.NotificationManager");
	var nm = main.getSystemService(Context.NOTIFICATION_SERVICE);

	var Notification = plus.android.importClass("android.app.Notification");
	var Intent = plus.android.importClass("android.content.Intent");
	var PendingIntent = plus.android.importClass("android.app.PendingIntent");
	var intent = new Intent(main, main.getClass());

	//传递参数  
	var payload = {
		'msg': content,
		'notify_id': NotifyID,
		'data': data
	};
	intent.putExtra("receive", JSON.stringify(payload));

	//PendingIntent.getActivity的第二个参数需要设置为随机数，否则多个通知时会导致前面的通知被后面的通知替换Extra的数据  
	var pendingIntent = PendingIntent.getActivity(main, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
	var SystemVersion = plus.os.version;
	var firstVersionNumber = Number(SystemVersion.split('.')[0]);
	var r = plus.android.importClass("android.R");
	var mNotification;

	//判断当前系统版本在8.0及以上  
	if (firstVersionNumber >= 8) {
		var NotificationChannel = plus.android.importClass('android.app.NotificationChannel');
		var channel = new NotificationChannel("s" + NotifyID, "1", NotificationManager.IMPORTANCE_HIGH);
		nm.createNotificationChannel(channel);
		Notification = plus.android.importClass("android.support.v4.app.NotificationCompat");
		mNotification = new Notification.Builder(main, "s" + NotifyID);
	} else {
		Notification = plus.android.importClass("android.app.Notification");
		mNotification = new Notification.Builder(main);
	}

	mNotification.setContentTitle(title) //设置标题  
	mNotification.setContentText(content); //设置内容  
	//mNotification.setSubText('');        //子内容暂时去掉  
	mNotification.setAutoCancel(true); //设置点击消失  
	mNotification.setShowWhen(true); //显示通知时间，貌似不加这句也能显示  
	mNotification.setTicker("PadInfo"); //弹出通知  
	mNotification.setSmallIcon(17301620); //设置当前app图标  
	//mNotification.setDefaults(Notification.DEFAULT_VIBRATE);  //声音、闪灯、震动效果，可叠加，此语句无效  
	mNotification.setPriority(Notification.PRIORITY_DEFAULT); //通知优先级    
	mNotification.flags = Notification.FLAG_ONLY_ALERT_ONCE; //发起通知时震动    
	mNotification.setContentIntent(pendingIntent);
	var mNb = mNotification.build();

	//判断当前系统版本在8.0及以上    
	if (firstVersionNumber >= 8) {
		nm.notify("s" + NotifyID, NotifyID, mNb);
	} else {
		nm.notify(NotifyID, mNb);
	}
	//void plus.device.beep(2);//bee bee叫  
	plus.device.vibrate(300); //震动  

	console.log('通知结束');
	return true;
	// #endif  
}
/**  
  * android原生通知接收  
  */  
export function android_receive() {  
  // #ifdef APP-PLUS  
  if (plus.os.name != 'Android') {  
   return false;  
  }  
  //android原生通知栏接收器（程序退出后无效）  
  var main = plus.android.runtimeMainActivity();  
  var intent = main.getIntent();  
  var message = intent && intent.getExtra != undefined ? intent.getExtra("receive") : null;  
  console.log(message);  
  message = message ? JSON.parse(message) : '';  
  if (message) {  
   //删除当前通知  
   // var Context = plus.android.importClass("android.content.Context");  
   // var nm = main.getSystemService(Context.NOTIFICATION_SERVICE);  
   // console.log(message.notify_id);  
   //nm.cancel('s' + message.notify_id, message.notify_id);//安卓版本大于等于8的  
   //nm.cancel(message.notify_id);//安卓版本小于8的  
   // nm.cancelAll();  

   //把消息数据置空，以免再次打开APP时重复执行此处  
   intent.putExtra("receive", '');  

   var params = message.data;  
   if (params1 == 'xxx') {  
    //TODO do something.  
   } else if (params1 == 'yyy') {  
    //TODO do something.  
   }  
  }  
  // #endif  
 }  